﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace ProgNetComponentsDx.Forms
{
    [TypeDescriptionProvider(typeof(AbstractFormTypeDescriptionProvider))]
    internal abstract partial class AbstractForm : Form
    {
        public AbstractForm()
        {
            InitializeComponent();
        }
        protected abstract bool IsOK
        {
            get;
        }
        internal class AbstractFormTypeDescriptionProvider : TypeDescriptionProvider
        {
            public AbstractFormTypeDescriptionProvider() :
                base(TypeDescriptor.GetProvider(typeof(AbstractForm)))
            {

            }

            public override object CreateInstance(IServiceProvider provider, Type objectType, Type[] argTypes, object[] args)
            {
                if (objectType == typeof(AbstractForm))
                    objectType = typeof(AbstractFormConcentrate);

                return base.CreateInstance(provider, objectType, argTypes, args);
            }

            public override Type GetReflectionType(Type objectType, object instance)
            {
                StackTrace st = new StackTrace();
                if (objectType == typeof(AbstractForm) && !st.ToString().Contains("System.ComponentModel.Design.InheritanceService.AddInheritedComponents"))
                    objectType = typeof(AbstractFormConcentrate);
                return base.GetReflectionType(objectType, instance);
            }
        }
    }

    internal class AbstractFormConcentrate : AbstractForm
    {
        protected override bool IsOK
        {
            get { throw new NotImplementedException(); }
        }
    }
}
